package com.bhkj.pdjhforotherapp.core.main.viewmodel;

import com.bhkj.pdjhforotherapp.R;
import com.bhkj.pdjhforotherapp.app.App;
import com.bhkj.pdjhforotherapp.common.Contact;
import com.bhkj.pdjhforotherapp.common.bean.MainYwAllBean;
import com.bhkj.pdjhforotherapp.common.parse.GsonProvider;
import com.bhkj.pdjhforotherapp.common.simpledisk.DiskLruCacheHelper;
import com.bhkj.pdjhforotherapp.common.utils.Tools;
import com.bhkj.pdjhforotherapp.core.main.handler.IMainYwHandlerContract;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import java.util.List;

public class MainYwViewModel {
    private IMainYwHandlerContract.IMainAllYwCallback iMainAllYwCallback;
    private String deptId = StringUtils.getString(R.string.deptId);

    public MainYwViewModel(IMainYwHandlerContract.IMainAllYwCallback iMainAllYwCallback) {
        this.iMainAllYwCallback = iMainAllYwCallback;
    }

    /**
     * 获取所有的业务
     */
    public void getAllYw() {
        String deviceId = Tools.getDeviceId();
        EasyHttp.get(Contact.GET_ALL_YW)
                .params("key", deviceId)
                .params("rsa", Tools.encodeRsa(deviceId))
                .params("deptid", StringUtils.getString(R.string.deptId))
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        e.printStackTrace();
                        if (iMainAllYwCallback != null) {
                            iMainAllYwCallback.onAllYwError(e);
                        }
                    }

                    @Override
                    public void onSuccess(String res) {
//                        LogUtils.i(res);
                        if (iMainAllYwCallback != null) {
                            iMainAllYwCallback.onAllYwSuccess(res);
                        }
                    }
                });

    }
}
